<?php
/**
 * 下载类
 *
 */
class Download {
    
    
    /**
     * 重置月,周,日下载次数
     *
     */
    public function resetdowninfo() {
        
        $dblink = new DataBase();
        $query = "select * from info where id = 1";
        $result = $dblink->query($query)->fetch();
        $last_visit = $result['last_visit'];
        $now_date = date('Y-m-d');
        if($last_visit != $now_date) {
            //重置日下载次数
            $query = "update books set day_down = '0'";
            $dblink->query($query);
            
            //重置周下载次数
            $last_week = date('W',time($last_visit));
            $now_week = date('W', time());
            if($last_week != $now_week) {
                $query = "update books set week_down = '0'";
                $dblink->query($query);
            }
            
            //重置月下载次数
            if(substr($now_date, 0, 7) != substr($last_visit, 0, 7)) {
                $query = "update books set month_down = '0'";
                $dblink->query($query);
            }
            
            //更新最后访问时间
            $query = "update info set last_visit = '$now_date'";
            $dblink->query($query);
        }
    }
}